package com.work.device.service.impl;

import com.work.device.mapper.IndexMapper;
import com.work.device.pojo.Index;
import com.work.device.service.IndexService;
import com.work.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {
    @Autowired
    private IndexMapper indexMapper;
    @Autowired
    private IdWorker idWorker;

    /**
     * 查询所有数据指标
     * @return  数据指标
     */
    @Override
    public List<Index> findAll() {
        List<Index> indixList = indexMapper.selectAll();
        return indixList;
    }

    /**
     * 根据id查询数据指标
     * @param id 数据指标id
     * @return
     */
    @Override
    public Index findById(Long id) {
        return indexMapper.selectByPrimaryKey(id);
    }

    /**
     * 添加数据指标
     * @param index 数据指标对象
     */
    @Override
    public void add(Index index) {
        long id = idWorker.nextId();
        index.setId(id);
        indexMapper.insertSelective(index);
    }


}
